<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>调试页面</title>
<%@ include file="/pages/wx/baseHead.jsp"%>

<script type="text/javascript">
	
	$(function(){
		initWxSdk();
		
		$("#validate").click(function(){
			var jv =$("#json_input").val();
			var jsObj = JSON.parse(jv);
			var jsObj = formatJson(jsObj);
			$("#json_input").val(jsObj);
		});
	});
	
	function initWxSdkOk()
	{
		$("#touchArea")[0].style.background = '#04BE02';
		$("#msg").html('点击扫描条形码/二维码');
		var barcode = '${barcode}';
	}
	
	function scan(type)
	{
		wx.scanQRCode({
		    needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
		    scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
		    success: function (res) {
		    	var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
		    	var tag = '#key'+type;
				var val = $(tag).val(result.split(",")[1]);
		    	loadOrder(type);
			}
		});
	}
	
	
	function loadOrder(type)
	{
		var tag = '#key'+type;
		var val = $(tag).val();
		if(isNull(val))
		{
			return;
		}
		to('${urlBasePath }weixin/user/debug.do?key='+val+'&type='+type);
	}
	
	
	var formatJson = function(json, options) {
		var reg = null,
			formatted = '',
			pad = 0,
			PADDING = '    '; // one can also use '\t' or a different number of spaces
	 
		// optional settings
		options = options || {};
		// remove newline where '{' or '[' follows ':'
		options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
		// use a space after a colon
		options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
	 
		// begin formatting...
		if (typeof json !== 'string') {
			// make sure we start with the JSON as a string
			json = JSON.stringify(json);
		} else {
			// is already a string, so parse and re-stringify in order to remove extra whitespace
			json = JSON.parse(json);
			json = JSON.stringify(json);
		}
	 
		// add newline before and after curly braces
		reg = /([\{\}])/g;
		json = json.replace(reg, '\r\n$1\r\n');
	 
		// add newline before and after square brackets
		reg = /([\[\]])/g;
		json = json.replace(reg, '\r\n$1\r\n');
	 
		// add newline after comma
		reg = /(\,)/g;
		json = json.replace(reg, '$1\r\n');
	 
		// remove multiple newlines
		reg = /(\r\n\r\n)/g;
		json = json.replace(reg, '\r\n');
	 
		// remove newlines before commas
		reg = /\r\n\,/g;
		json = json.replace(reg, ',');
	 
		// optional formatting...
		if (!options.newlineAfterColonIfBeforeBraceOrBracket) {			
			reg = /\:\r\n\{/g;
			json = json.replace(reg, ':{');
			reg = /\:\r\n\[/g;
			json = json.replace(reg, ':[');
		}
		if (options.spaceAfterColon) {			
			reg = /\:/g;
			json = json.replace(reg, ':');
		}
	 
		$.each(json.split('\r\n'), function(index, node) {
			var i = 0,
				indent = 0,
				padding = '';
	 
			if (node.match(/\{$/) || node.match(/\[$/)) {
				indent = 1;
			} else if (node.match(/\}/) || node.match(/\]/)) {
				if (pad !== 0) {
					pad -= 1;
				}
			} else {
				indent = 0;
			}
	 
			for (i = 0; i < pad; i++) {
				padding += PADDING;
			}
	 
			formatted += padding + node + '\r\n';
			pad += indent;
		});
	 
		return formatted;
	};

	
	
</script>

</head>
<body>
<div class="alert alert-info" role="alert">
	<div class="input-group margin-bottom-sm form-inline has-success">
		<span class="input-group-addon" onclick="scan();"><i class="fa fa-qrcode fa-fw"></i>&nbsp;</span>
	  <input class="form-control col-md-3" type="text" 
	  value='<c:choose><c:when test="${key1 == null || key == '' }">EEI</c:when><c:otherwise>${key1 }</c:otherwise></c:choose>'  
	  id="key1" placeholder="请输入订单号" style="height: 46px;z-index: 1;" >
	  <span class="input-group-addon"><a href="javascript:void(0);"  onclick="loadOrder(1);">
	  	<i class="fa fa-search fa-sm"></i></a>
	  </span>
	  </span>
	</div>
	
	<div class="input-group margin-bottom-sm form-inline has-success" style="padding-top: 10px;">
		<span class="input-group-addon" onclick="scan(2);"><i class="fa fa-qrcode fa-fw"></i>&nbsp;</span>
	  <input class="form-control col-md-3" type="text" value="${key2 }"  id="key2" placeholder="请输入条形码" style="height: 46px;z-index: 1;" >
	  <span class="input-group-addon"><a href="javascript:void(0);"  onclick="loadOrder(2);">
	  	<i class="fa fa-search fa-sm"></i></a>
	  </span>
	  </span>
	</div>
	
	<div class="input-group margin-bottom-sm form-inline has-success"  style="padding-top: 10px;">
		<span class="input-group-addon" onclick="scan(3);"><i class="fa fa-qrcode fa-fw"></i>&nbsp;</span>
	  <input class="form-control col-md-3" type="text" value="${key3 }" id="key3" placeholder="请输入快递单" style="height: 46px;z-index: 1;" >
	  <span class="input-group-addon"><a href="javascript:void(0);" onclick="loadOrder(3);">
	  	<i class="fa fa-search fa-sm"></i></a>
	  </span>
	  </span>
	</div>
</div>
<div class="weui_msg" style="margin-top: -20px;">
	   <!-- <div class="weui_icon_area"><i class="weui_icon_safe_warn weui_icon_msg"></i></div> -->
	   <div class="weui_text_area">
	       <p class="weui_msg_desc">
	       		<textarea id="json_input" class="form-control" rows="10">${ret }</textarea>
	       		<br>
	       		<button id="validate" class="weui_btn weui_btn_primary">校验</button>
	       </p>
	   </div>
	</div>

<!-- 引入微信样式代码提示工具开始 -->
<%@ include file="/pages/wx/wxClass.jsp"%>
<!-- 引入微信样式代码提示工具结束 -->
<%@ include file="/pages/wx/baseBottom.jsp"%>
</body>
</html>

